`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    15:29:48 08/31/2014 
// Design Name: 
// Module Name:    ecc_correction 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module ecc_correction(
    input [31:0] data,
    input [7:0] ecc_code,
    output [31:0] data_corrected
    );

	wire [7:0] ecc_cal;
	
	ecc_cal entity_ecc_cal (
		.data (data),
		.ecc_code (ecc_cal)
	);

	wire [2:0] col;
	wire [1:0] row;
	wire [7:0] err;
	wire [31:0] corrected;
	assign err = ecc_code ^ ecc_cal;
	assign col = err[2:0];
	assign row = err[4:3];
	assign corrected = data ^ (1 << ((row << 3) + col));
	
	assign data_corrected = (err == 0) ? data : corrected;
endmodule
